package main
//生成待评价任务
//@author liyang<654516092@qq.com>
import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/comment"
	"git.900sui.cn/kc/rpcinterface/client/order"
	comment2 "git.900sui.cn/kc/rpcinterface/interface/comment"
	order2 "git.900sui.cn/kc/rpcinterface/interface/order"
	"github.com/streadway/amqp"
	"strconv"
)

func main(){
	rpcOrder := new(order.CardPackage).Init()
	defer  rpcOrder.Close()
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("queue.log.serviceTobeComment"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("queue.serviceTobeComment"), func(msg amqp.Delivery) {
		logId,_:= strconv.Atoi(string(msg.Body))
		reply := order2.ReplyConsumeDataList{}
		if err := rpcOrder.GetSingleConsumeLog(context.Background(),&logId,&reply);err != nil{
			utils.Logerr.Printf("获取消费记录错误，logsId:%s, err:%s", logId, err)
		}
		//继续写业务逻辑
		rpcComments := new(comment.ServiceBeComment).Init()
		defer rpcComments.Close()
		argsBe := comment2.ArgsAddServiceBeComment{
			BusId:           reply.BusId,
			ShopId:          reply.ShopId,
			Uid:             reply.Uid,
			RelationId:      reply.RelationId,
			CardPackageId:   reply.CardPackageId,
			CardPackageType: reply.CardPackageType,
		}
		singles := make([]comment2.ConsumeSingle,0)
		for _,m := range reply.ConsumeDataConf{
			if m.Type == order2.CARDPACKAGE_consume_product{
				continue
			}
			for i:=0;i<m.Num;i++{
				o := comment2.ConsumeSingle{
					SingleId:   m.SingleId,
					SingleName: m.SingleName,
					SspId:      m.SspId,
					SspName:    m.SspName,
					Num:        1,
					Price:      m.Price,
					ImgId:      0,
				}
				if len(m.StaffId)>0{
					o.StaffId = m.StaffId[i]
				}
				singles = append(singles,o)
			}
		}
		argsBe.Singles = singles
		replyToBe := comment2.ReplyAddServiceBeComment{}
		if err := rpcComments.AddServiceBeCommentRpc(context.Background(),&argsBe,&replyToBe);err != nil{
			utils.Logerr.Printf("生成待评价任务错误，logsId:%s, err:%s", logId, err)
		}
		if replyToBe.Result{
			utils.Logerr.Printf("生成待评价任务成功，logsId:%s", logId)
		}
		//\\继续写业务逻辑
	})
	if err != nil {
		utils.Logerr.Printf("任务失败，err: %s", err.Error())
	}
}

